﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebFormTours.aspx.cs" Inherits="TravelAgency.WebFormTours" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="ContentHead" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="ContentBody" ContentPlaceHolderID="ContentPlaceHolder" runat="server">
    <div>
        <asp:UpdatePanel ID="UpdatePanelAllTours" runat="server">
            <ContentTemplate>
                All tours:
                <asp:GridView ID="GridViewTours" runat="server" 
                    DataSourceID="LinqDataSourceTours" AllowPaging="True" 
                    AutoGenerateColumns="False" PageSize="2"
                    onrowdatabound="GridViewTours_RowDataBound" >
                    <Columns>                        
                        
                        <asp:TemplateField HeaderText="Destination">
                            <ItemTemplate>
                                <%# Eval("Destination.Name") %>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="StartDate" HeaderText="Start date" ReadOnly="True" 
                            SortExpression="StartDate" DataFormatString="{0:d}" />
                        <asp:BoundField DataField="EndDate" HeaderText="End date" ReadOnly="True" 
                            SortExpression="EndDate" DataFormatString="{0:d}" />
                        <asp:BoundField DataField="Price" HeaderText="Price" ReadOnly="True" 
                            SortExpression="Price" DataFormatString="{0:c}" />  
                    </Columns>            
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:UpdatePanel ID="UpdatePanelSearch" runat="server">
            <ContentTemplate>
                Search by:
                <div id="divSearch" runat="server" style="border:1px solid black">
                    <asp:CheckBox ID="CheckBoxDestination" runat="server" Text="Destination"/>
                    <asp:DropDownList ID="DropDownDestination" runat="server" 
                        DataSourceID="LinqDataSourceDestinations" DataValueField="DestinationID"
                        DataTextField="Name"></asp:DropDownList> <hr />
                    <asp:CheckBox ID="CheckBoxPrice" runat="server" Text="Price"/> <br />
                    from <asp:TextBox ID="TextBoxMinPrice" runat="server"></asp:TextBox>
                    <asp:RangeValidator ID="MinPriceValidator" runat="server" 
                        ControlToValidate="TextBoxMinPrice" Type="Currency"
                        MinimumValue="0" MaximumValue="1000000" 
                        ForeColor="Red" ErrorMessage="Not valid price!"></asp:RangeValidator>
                    to <asp:TextBox ID="TextBoxMaxPrice" runat="server"></asp:TextBox> 
                    <asp:RangeValidator ID="MaxPriceValidator" runat="server" 
                        ControlToValidate="TextBoxMaxPrice" Type="Currency"
                        MinimumValue="0" MaximumValue="1000000" 
                        ForeColor="Red" ErrorMessage="Not valid price!"></asp:RangeValidator><hr />                    
                    <asp:CheckBox ID="CheckBoxDate" runat="server" Text="Date(format: DD-MM-YYYY)"/> <br />
                    start date <asp:TextBox ID="TextBoxStartDate" runat="server"></asp:TextBox> 
                    <asp:CalendarExtender ID="CalendarExtenderStartDate" runat="server" 
                    TargetControlID="TextBoxStartDate"></asp:CalendarExtender>
                    end date <asp:TextBox ID="TextBoxEndDate" runat="server"></asp:TextBox>
                    <asp:CalendarExtender ID="CalendarExtenderEndDate" runat="server" 
                    TargetControlID="TextBoxEndDate"></asp:CalendarExtender> <hr />
                    <asp:CheckBox ID="CheckBoxReferenceNumer" runat="server" Text="Reference number" />
                    <asp:TextBox ID="TextBoxReferenceNumber" runat="server"></asp:TextBox> <br />
                    <asp:Button ID="ButtonSearch" runat="server" Text="Search" 
                        onclick="ButtonSearch_Click" />
                </div>
                <asp:Repeater ID="RepeaterTours" runat="server">
                    <HeaderTemplate>
                        <b>Results:</b> <br />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <b>Destination: </b>  <%# GetDestination((int)Eval("DestinationID"))%> <br />
                        <b>Starts: </b> <%# Eval("StartDate", "{0:dd/MM/yyyy}") %> <br />
                        <b>Ends: </b> <%# Eval("EndDate", "{0:dd/MM/yyyy}")%> <br />
                        <b>Price: </b> <%# Eval("Price","{0:c}") %> <br />
                        <asp:HyperLink ID="HyperLink" runat="server" NavigateUrl='<%# Eval("TourID", "WebFormDetails.aspx?TourID={0}") %>' Text="Details"/>
                        <hr />
                    </ItemTemplate>                                        
                </asp:Repeater>
                <asp:Label ID="LabelNoResult" runat="server" Text=""></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:LinqDataSource ID="LinqDataSourceTours" runat="server" EntityTypeName="" 
            ContextTypeName="DAOTAgency.TAgencyDataContext" 
            Select="new (StartDate, EndDate, Price, Description, Destination, DestinationID, TourID)" 
            TableName="Tours" Where="Visible = True" OrderBy="StartDate">
        </asp:LinqDataSource>
        <asp:LinqDataSource ID="LinqDataSourceDestinations" runat="server" 
            ContextTypeName="DAOTAgency.TAgencyDataContext"
            Select="new (Name, DestinationID)" TableName="Destinations" 
            EntityTypeName="">
        </asp:LinqDataSource>
    </div>
</asp:Content>
